<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <div>
        <el-form-item label="交易流水号">
          <el-input v-model="queryParams.orderNo" placeholder="" clearable></el-input>
        </el-form-item>

        <el-form-item label="结算金额">
          <el-input v-model="queryParams.finalAmount" placeholder="" clearable></el-input>
        </el-form-item>

        <el-form-item label="支付金额">
          <el-input v-model="queryParams.payAmount" placeholder="" clearable></el-input>
        </el-form-item>
      </div>

      <div>
        <el-form-item label="业务订单号">
          <el-input v-model="queryParams.payOrderNo" placeholder="" clearable></el-input>
        </el-form-item>
        <el-form-item label="交易对手">
          <el-input v-model="queryParams.tradeUser" placeholder="" clearable></el-input>
        </el-form-item>
        <el-form-item label="发起交易日期">
          <el-date-picker
            clearable
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="queryParams.tradeDateFq"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
          <span>至</span>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="queryParams.tradeDateFq1"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </div>
      <div>
        <el-form-item label="交易账户">
          <el-input v-model="queryParams.tradeAccount" placeholder="" clearable></el-input>
        </el-form-item>
        <el-form-item label="对手账户">
          <el-input v-model="queryParams.dsAccount" placeholder="" clearable></el-input>
        </el-form-item>
        <el-form-item label="支付截至日期">
          <el-date-picker
            clearable
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="queryParams.tradeDateJz"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
          <span>至</span>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="queryParams.tradeDateJz1"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
      </div>

      <div>
        <el-form-item label="交易账户">
          <el-input v-model="queryParams.tradeAccountNo" placeholder="" clearable></el-input>
        </el-form-item>
        <el-form-item label="交易渠道">
          <el-input v-model="queryParams.tradeQudao" placeholder="" clearable></el-input>
        </el-form-item>
      </div>

      <div>
        <el-form-item label="交易账户类型">
          <el-select v-model="queryParams.tradeAccountType" placeholder="请选择" clearable>
            <el-option v-for="item in tradeAccountTypeList" :label="item.dictLabel" :value="item.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="渠道订单号">
          <el-input v-model="queryParams.qudaoOrderNo" placeholder="" clearable></el-input>
        </el-form-item>
      </div>

      <div>
        <el-form-item label="用户类型">
          <el-select v-model="queryParams.userType" placeholder="请选择" clearable>
            <el-option v-for="item in userTypeList" :label="item.dictLabel" :value="item.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交易结果">
          <el-select v-model="queryParams.tradeResult" placeholder="请选择" clearable>
            <el-option v-for="item in tradeResultList" :label="item.dictLabel" :value="item.dictValue"></el-option>
          </el-select>
        </el-form-item>
      </div>

      <div>
        <el-form-item label="支付方式">
          <el-select v-model="queryParams.payWay" placeholder="请选择" clearable>
            <el-option v-for="item in payWayList" :label="item.dictLabel" :value="item.dictValue"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单金额">
          <el-input v-model="queryParams.amount" placeholder="" clearable></el-input>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="交易流水号" align="center" prop="orderNo" />
      <!--业务订单号-->
      <el-table-column label="交易流水号" align="center" prop="payOrderNo" />
      <el-table-column label="交易账户类型" align="center" prop="tradeAccountType">
        <template slot-scope="scope">
          <span v-for="item in tradeAccountTypeList" v-if="scope.row.tradeAccountType==item.dictValue">{{item.dictLabel}}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户类型" align="center" prop="userType">
        <template slot-scope="scope">
          <span v-for="item in userTypeList" v-if="scope.row.userType==item.dictValue">{{item.dictLabel}}</span>
        </template>
      </el-table-column>
      <el-table-column label="交易账号" align="center" prop="tradeAccountNo" />
      <el-table-column label="交易账户" align="center" prop="tradeAccount" />
      <el-table-column label="支付方式" align="center" prop="payWay">
        <template slot-scope="scope">
          <span v-for="item in payWayList" v-if="scope.row.payWay==item.dictValue">{{item.dictLabel}}</span>
        </template>
      </el-table-column>
      <el-table-column label="结算金额" align="center" prop="finalAmount" />
      <el-table-column label="交易对手" align="center" prop="tradeUser" />
      <el-table-column label="对手账号" align="center" prop="dsAccount" />
      <el-table-column label="交易渠道" align="center" prop="tradeQudao" />
      <el-table-column label="渠道订单号" align="center" prop="qudaoOrderNo" />
      <el-table-column label="交易结果" align="center" prop="tradeResult">
        <template slot-scope="scope">
          <span v-for="item in tradeResultList" v-if="scope.row.tradeResult==item.dictValue">{{item.dictLabel}}</span>
        </template>
      </el-table-column>
      <el-table-column label="返回码" align="center" prop="returnCode" />
      <el-table-column label="返回信息" align="center" prop="returnMsg" />
      <el-table-column label="发起交易日期" align="center" prop="tradeDateFq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateFq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="执行交易日期" align="center" prop="tradeDateZx" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateZx, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付截止日期" align="center" prop="tradeDateJz" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tradeDateJz, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="费率" align="center" prop="tradeRate" />
      <el-table-column label="手续费" align="center" prop="commissionFee" />
      <el-table-column label="订单金额" align="center" prop="amount" />
      <el-table-column label="支付金额" align="center" prop="payAmount" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder,dictInfo } from "@/api/finance/order";

export default {
  name: "Order",
  components: {
  },
  data() {
    return {
      //交易账户类型集合
      tradeAccountTypeList:[],
      //用户类型
      userTypeList:[],
      //交易结果
      tradeResultList:[],
      //支付方式
      payWayList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付订单（支付流水信息）表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        tradeAccount: null,
        tradeAccountType: null,
        tradeAccountNo: null,
        userId: null,
        userType: null,
        operationType: null,
        payWay: null,
        amount: null,
        payAmount: null,
        finalAmount: null,
        discountAmount: null,
        tradeUser: null,
        dsAccount: null,
        tradeQudao: null,
        qudaoOrderNo: null,
        tradeResult: null,
        returnCode: null,
        returnMsg: null,
        tradeDateFq: null,
        tradeDateZx: null,
        tradeDateZf: null,
        tradeDateJz: null,
        tradeRate: null,
        commissionFee: null,
        beginTime: null,
        endTime: null,
        checkState: null,
        checkTime: null,
        checkUserid: null,
        checkFailReason: null,
        outOrderNo: null,
        dzState: null,
        certificateJz: null,
        productSubject: null,
        productBody: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNo: [
          { required: true, message: "支付订单号不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户ID：根据类型来判断是哪种客户的ID(不一定是登录客户，而是这笔交易的对象)租客付款的时候，是租客，企业充值提现是企业businessid不能为空", trigger: "blur" }
        ],
        userType: [
          { required: true, message: "交易涉及用户类型：1：租客个人用户不能为空", trigger: "change" }
        ],
        operationType: [
          { required: true, message: "操作类型：1：充值不能为空", trigger: "change" }
        ],
        amount: [
          { required: true, message: "订单金额：支付订单金额不能为空", trigger: "blur" }
        ],
        beginTime: [
          { required: true, message: "开始时间，设定为记录创建时间，作为业务开始时间不能为空", trigger: "blur" }
        ],
        productSubject: [
          { required: true, message: "商品信息不能为空", trigger: "blur" }
        ],
        productBody: [
          { required: true, message: "商品信息不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识。0:未删除，1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDict();
  },
  methods: {
    //获取字典表数据
    getDict() {
      dictInfo().then(res=>{
        this.tradeAccountTypeList=res.data.tradeAccountTypeList.data
        this.userTypeList=res.data.userTypeList.data
        this.tradeResultList=res.data.tradeResultList.data
        this.payWayList=res.data.payWayList.data
      })
    },

    /** 查询支付订单（支付流水信息）列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        tradeAccount: null,
        tradeAccountType: null,
        tradeAccountNo: null,
        userId: null,
        userType: null,
        operationType: null,
        payWay: null,
        amount: null,
        payAmount: null,
        finalAmount: null,
        discountAmount: null,
        tradeUser: null,
        dsAccount: null,
        tradeQudao: null,
        qudaoOrderNo: null,
        tradeResult: null,
        returnCode: null,
        returnMsg: null,
        tradeDateFq: null,
        tradeDateZx: null,
        tradeDateZf: null,
        tradeDateJz: null,
        tradeRate: null,
        commissionFee: null,
        beginTime: null,
        endTime: null,
        checkState: null,
        checkTime: null,
        checkUserid: null,
        checkFailReason: null,
        outOrderNo: null,
        dzState: null,
        certificateJz: null,
        productSubject: null,
        productBody: null,
        canClearingAmount: null,
        remarks: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支付订单（支付流水信息）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改支付订单（支付流水信息）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除支付订单（支付流水信息）编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delOrder(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/order/export', {
        ...this.queryParams
      }, `finance_order.xlsx`)
    }
  }
};
</script>
